<?php
/**
* 
* @var $model Page
*/
$model;
static $baseScriptUrl;
if (!isset($baseScriptUrl))
    $baseScriptUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets')).'/gridview';
?>
<table class="items">
    <tr class="<?php echo $class;?>">
        <td align="center" class="checkbox-column"><?php echo CHtml::checkBox('item', false, array('value'=>$model->id, 'class'=>'select-on-check'));?></td>
        <td class="sort-handle">
            <?php echo $hasChild ? CHtml::link('Toggle', '#', array('class'=>'collapse')) : '';?>
            <?php
            $lastestPageRevision = PageRevision::model()->find(array('condition'=>'page_id=:pageId','order'=>'id DESC','params'=>array(':pageId'=>$model->id)));
            if (!is_null($lastestPageRevision))
                $lastestPageRevisionId = $lastestPageRevision->id;
            else
                $lastestPageRevisionId = 1;        
            echo CHtml::link($model->title, array("/Cms/admin/pageRevision/template", 'revision_id'=>$lastestPageRevisionId, "page_id"=>$model->id), array('title'=>'Updated: '.Yii::app()->getDateFormatter()->formatDateTime(strtotime($model->last_update)).' - Created: '.Yii::app()->getDateFormatter()->formatDateTime(strtotime($model->creation_datetime))));?>
        </td>
        <td align="left" width="202"><div><span><?php echo $model->note;?></span> <?php echo CHtml::link(CHtml::image($baseScriptUrl."/update.png", "Edit Note"), array("editLog", "id"=>$model->id), array("class"=>"edit-log", "title"=>"Edit Note"));?></div></td>
        <td width="201">
            <?php //echo is_object($model->defaultUrl) ? CHtml::link($model->defaultUrl->url, Yii::app()->request->hostInfo . Yii::app()->request->baseUrl ."/". ltrim($model->defaultUrl->url, "/"), array("target"=>"_blank")) : "";?>
            <?php echo is_object($model->defaultUrl) ? $model->defaultUrl->url : "";?><br />
            (<?php echo $model->alias;?>)
        </td>
        <td width="37" align="center">
            <?php echo CHtml::image(Yii::app()->theme->baseUrl.'/images/'.(FSM::_run('Cms.workflow.isActiveInLive', array('page_id'=>$model->id))->status ? 'log_severity1' : 'delicon').'.gif', 'Live');?>
        </td>
        <td align="center" class="status-column" style="width: 72px;">
            <?php echo CHtml::link($model->statusText,
                array(
                    "/Core/service/ajax", 
                    'SID'=>'Cms.page.includeInSitemap', 
                    "ids[]"=>$model->id, 
                    "value"=>$model->include_in_sitemap ? 0 : 1
                ),
                array(
                    "class"=>($model->include_in_sitemap ? "active" : "")
                )
            );?>
        </td>
        <td align="center" class="status-column">
            <?php echo CHtml::link($model->statusText,
                array(
                    "/Core/service/ajax", 
                    'SID'=>'Cms.page.changeStatus', 
                    "ids[]"=>$model->id, 
                    "value"=>$model->status ? 0 : 1
                ),
                array(
                    "class"=>($model->status ? "active" : "")
                )
            );?>
        </td>
        <td width="101" align="center" class="actions-column">
            <?php if($model->type!=Page::TYPE_GROUP):?>
            <?php echo CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/duplicate-page.png', 'Duplicate'), '#'.$model->id, array('title'=>'Duplicate', 'class'=>'duplicate'));?>
            
            <?php echo CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/copy-page.png', 'Copy'), '#'.$model->id, array('title'=>'Copy', 'class'=>'copy'));?>
            
            <?php echo CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/link-go.png', 'Go to'), (is_object($model->defaultUrl) && is_object($lastestRevision = $model->lastestRevision) ? Yii::app()->request->hostInfo."/".trim($model->defaultUrl->url, "/")."?revision=".$lastestRevision->id : "#"), array('target'=>'_blank'));?>
            <?php endif;?>
            <?php echo CHtml::link(CHtml::image($baseScriptUrl.'/update.png', 'Edit'), array('update', 'id'=>$model->id), array('title'=>'Edit'));?>
            
            <?php echo CHtml::link(CHtml::image($baseScriptUrl.'/delete.png', 'Delete'), array('delete', 'ids[]'=>$model->id), array('class'=>'delete', 'title'=>'Delete'));?>
        </td>
    </tr>
</table>